﻿Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class MessageBox
   
#Region "MessageBox"
    Enum Modi
        SpielerAendern
        MessageBox
        OpenDialog
        SaveDialog
        OrdnerDialog
        ColorDialog
        ConnectToHost
        KeyInput
        LoadUnit
    End Enum
    Public Shared Modus As Modi
    ''' <summary>
    ''' Result for Output
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Result As MsgBoxResult = MsgBoxResult.Abort
    ''' <summary>
    ''' Already clicked?
    ''' </summary>
    ''' <remarks></remarks>
    Shared GetResult As Boolean = False
    ''' <summary>
    ''' Our Class current Dialog\Menu
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared MessageDialogueBox As MessageBox = Nothing
    Public Shared ObjekteLocker As New Mutex
    ''' <summary>
    ''' All Objects of this Box
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Objekte As New List(Of Objekt2D)
    ''' <summary>
    ''' Die Ausdehnung dieser Box
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Dimension As Rectangle
    ''' <summary>
    ''' Schrift mit der,der Text gemalt wird.
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared FontID As Integer = -1
    ''' <summary>
    ''' Die Groesse der Schrift
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared FontDimension As Size
    ''' <summary>
    ''' Creates a Messagebox for the Game.
    ''' </summary>
    ''' <param name="Message"></param>
    ''' <param name="Buttons"></param>
    ''' <param name="Title"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ShowMessageBox(ByVal Message As Object, Optional ByVal Buttons As Microsoft.VisualBasic.MsgBoxStyle = MsgBoxStyle.OkOnly, Optional ByVal Title As Object = Nothing) As MsgBoxResult
        If Grafikengine.Grafikkarte Is Nothing Then
            Return MsgBox(Message, Buttons, Title)
        Else
            Modus = Modi.MessageBox
            MessageDialogueBox = New MessageBox

            Result = MsgBoxResult.Abort
            GetResult = False
            Dimension = New Rectangle(DataSettings.BildschirmBreite / 3, DataSettings.BildschirmHoehe / 3, DataSettings.BildschirmBreite / 3, DataSettings.BildschirmHoehe / 3)
            If Dimension.Width < 230 Then Dimension.Width = DataSettings.BildschirmBreite

            FontID = Schriftengine.CreateSchriftart(Schriftengine.Schriftarten.Courier_New, 10, FontStyle.Regular)
            FontDimension = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, "A", Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Size
            Dim Text As String() = ObjektText.getStringsZeilenweise(Sprachconverter.Translate(Message), Schriftengine.Fonts(FontID).GetFont, Dimension.Width - 10)
            Dimension.Height = (Text.Length + 2) * (FontDimension.Height + 3) + 30
            If Dimension.Height + Dimension.Y > DataSettings.BildschirmHoehe Then
                Dimension.Y = (DataSettings.BildschirmHoehe - Dimension.Height) / 2
            End If
            'Headline
            Dim Headline As String = ""
            If Title IsNot Nothing Then Headline = Title.ToString
            Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Headline}, New Point(0, 0), 10, 0, New PointF))
            Objekte(0).Rechteck = New Rectangle(Objekte(0).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

            Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5 + 15, DataSettings.Resourcenpfad + "Objects\Transparent.png", Text, New Point(1, 1), 10, 0, New PointF))

            Select Case Buttons
                Case MsgBoxStyle.YesNo
                    MessageBox.Result = MsgBoxResult.No
                    Objekte.Add(New ObjektButton(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Ja", New PointF))
                    Objekte.Add(New ObjektButton(Dimension.X + 10 + 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Nein", New PointF))
                Case MsgBoxStyle.Exclamation, MsgBoxStyle.Critical, MsgBoxStyle.Information
                    MessageBox.Result = MsgBoxResult.Ok
                    Objekte.Add(New ObjektButton(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))
                Case MsgBoxStyle.OkCancel
                    MessageBox.Result = MsgBoxResult.Cancel
                    Objekte.Add(New ObjektButton(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))
                    Objekte.Add(New ObjektButton(Dimension.X + 10 + 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
                Case MsgBoxStyle.OkOnly
                    MessageBox.Result = MsgBoxResult.Ok
                    Objekte.Add(New ObjektButton(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))
            End Select

            Updateframe()

            Return MessageBox.Result
        End If
    End Function
    Public Shared Function ShowEnterText(ByVal Info As String, ByVal Textname As String) As MsgBoxResult
        Modus = Modi.MessageBox
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False

        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 150
        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 72
        Dimension = New Rectangle(X1, Y1, 300, 145)
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Info}, New Point(0, 0), 10, 0, New PointF))
        Objekte(0).Rechteck = New Rectangle(Objekte(0).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

        Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))
        'Label
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate(Textname) + ":"}, New Point(0, 0), 10, 0, New PointF()))
        Objekte.Add(New ObjektTextbox(Dimension.X + 60, Dimension.Y + 30, Dimension.Width - 20 - 60, New PointF))

        Updateframe()

        Return MessageBox.Result
    End Function
#End Region
#Region "Dialogfeld"
    ''' <summary>
    ''' Der momentan Angezeigte Pfad
    ''' </summary>
    ''' <remarks></remarks>
    Shared CurrentFolder As String
    ''' <summary>
    ''' Die momentan Ausgewaehlte Datei.
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared CurrentFile As String
    ''' <summary>
    ''' Die momentan Angezeigten Dateien und Ordner.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared CurrentFiles As New List(Of String)
    ''' <summary>
    ''' Die momentanen Filter
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared CurrentFilter As String
    ''' <summary>
    ''' Das DropDownMenue fuer den Filter
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared FilterBox As Integer
    ''' <summary>
    ''' Die momentane File Textbox.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared CurrentFileTextbox As Integer
    ''' <summary>
    ''' Der momentan Ausgewaehlte Dateipfad.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared CurrentFolderTextbox As Integer
    ''' <summary>
    ''' Die maximale Anzahl an Dateien.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared MaxShownItems As Integer
    ''' <summary>
    ''' Position des Scrollbars.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared ScrollBarPos As Integer
    ''' <summary>
    ''' Zum Anzeigen der Dateien.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared Text As ObjektText
    ''' <summary>
    ''' An dieser Stelle muessen wir eine Box fuer den ausgewaehlten Text malen...
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared CurrentSelectedFolder As Integer
    ''' <summary>
    ''' Ersschafft ein Dialogfeld zum speichern oder Oeffnen
    ''' </summary>
    ''' <param name="Dialog"></param>
    ''' <param name="Filter">For example "Commander Wars Maps ; *.map ; *.sav" First Description Afterwards Filter</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ShowOpenSaveDialogue(ByVal Dialog As Modi, ByVal Title As String, ByVal Startpath As String, ByVal Filter() As String, Optional ByVal StartFile As String = "") As MsgBoxResult
        Modus = Dialog
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Cancel
        GetResult = False
        CurrentFileTextbox = -1
        'Dimension bestimmen.
        Dimension = New Rectangle(DataSettings.BildschirmBreite / 3, DataSettings.BildschirmHoehe / 4, DataSettings.BildschirmBreite / 3, DataSettings.BildschirmHoehe / 2)
        If Dimension.Width < 330 Then
            Dimension.Width = DataSettings.BildschirmBreite
            Dimension.X = 0
        End If
        If Dimension.Height < 300 Then
            Dimension.Height = DataSettings.BildschirmHoehe
            Dimension.Y = 0
        End If
        FontID = Schriftengine.CreateSchriftart(Schriftengine.Schriftarten.Courier_New, 10, FontStyle.Regular)
        FontDimension = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, "A", Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Size

        'Headline
        Dim Headline As String = ""
        If Title IsNot Nothing Then Headline = Title.ToString
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Headline}, New Point(0, 0), 10, 0, New PointF))
        Objekte(0).Rechteck = New Rectangle(Objekte(0).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

        'Buttons

        Select Case Modus
            Case Modi.SaveDialog
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 60, DataSettings.Resourcenpfad + "Objects\Button.png", "Speichern", New PointF))
                'Textbox fuer die momentane Karte.
                Objekte.Add(New ObjektTextbox(Dimension.X + 10, Dimension.Y + Dimension.Height - 60, Dimension.Width - 20 - 125, New PointF))
                CurrentFileTextbox = Objekte.Count - 1
                CType(Objekte(CurrentFileTextbox), ObjektTextbox).SetText(StartFile)
            Case Modi.OrdnerDialog
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 60, DataSettings.Resourcenpfad + "Objects\Button.png", "Oeffnen", New PointF))
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
            Case Else
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
                Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 60, DataSettings.Resourcenpfad + "Objects\Button.png", "Oeffnen", New PointF))
                'Textbox fuer die momentane Karte.
                Objekte.Add(New ObjektTextbox(Dimension.X + 10, Dimension.Y + Dimension.Height - 60, Dimension.Width - 20 - 125, New PointF))
                CurrentFileTextbox = Objekte.Count - 1
        End Select
        'Dropdownmenue
        If Filter IsNot Nothing Then
            If Filter.Length > 0 Then
                Objekte.Add(New ObjektDropDownMenue(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, Filter, New PointF))
                CType(Objekte(Objekte.Count - 1), ObjektDropDownMenue).SetItem(0)
                FilterBox = Objekte.Count - 1
                CurrentFilter = Filter(0)
            Else
                FilterBox = -1
            End If
        Else
            FilterBox = -1
        End If

        'Textbox fuer momentanen Ordner
        Objekte.Add(New ObjektTextbox(Dimension.X + 10, Dimension.Y + 25, Dimension.Width - 20, New PointF))
        CurrentFolderTextbox = Objekte.Count - 1
        'UpDown Regler fuer die Dateien.
        Objekte.Add(New ObjektYScrollbar(0, Dimension.Height - 143, Dimension.Location + New Point(Dimension.Width - 30, 55), New PointF))
        ScrollBarPos = Objekte.Count - 1
        MaxShownItems = Math.DivRem((Dimension.Height - 120), FontDimension.Height, 0)
        Text = New ObjektText(New String() {}, 0, 0, Nothing, Schriftengine.Schriftarten.Courier_New, 10, FontStyle.Regular, , 0)
        ChangeCurrentFolder(Startpath)
        ChangeCurrentFile(StartFile)

        Updateframe()

        Return MessageBox.Result
    End Function
    ''' <summary>
    ''' Die letzten durchgegangenen Ordner
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared LastDirectories As New Stack(Of String)
    ''' <summary>
    ''' Ob wir die LastDirectories loeschen koennen.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared MovedBackward As Boolean = False
    ''' <summary>
    ''' Doppelt geklickt?
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared DoubleClick As Boolean = False
    ''' <summary>
    ''' Waehlt diesen Ordner aus.
    ''' </summary>
    ''' <param name="Folder"></param>
    ''' <remarks></remarks>
    Private Shared Sub ChangeCurrentFolder(ByVal Folder As String, Optional ByVal ClearLastDirectories As Boolean = True)
        CurrentFiles.Clear()
        CurrentFiles.Add(".") 'Zum letzten Ordner...
        If My.Computer.FileSystem.DirectoryExists(Folder) Then
            CurrentFolder = Folder
            CType(Objekte(CurrentFolderTextbox), ObjektTextbox).SetText(Folder)
            CurrentFiles.Add("..") 'Uebergeordneter Ordner...
            For Each Fol In My.Computer.FileSystem.GetDirectories(CurrentFolder, FileIO.SearchOption.SearchTopLevelOnly)
                CurrentFiles.Add(Fol)
            Next
            If Modus <> Modi.OrdnerDialog Then
                Dim Cards As String() = CurrentFilter.Split(";")
                Dim WildCard(Cards.Length - 2) As String
                For I = 1 To Cards.Length - 1
                    WildCard(I - 1) = Cards(I).Trim
                Next
                For Each File In My.Computer.FileSystem.GetFiles(CurrentFolder, FileIO.SearchOption.SearchTopLevelOnly, WildCard)
                    CurrentFiles.Add(File)
                Next
            End If
            CurrentSelectedFolder = -1
            CType(Objekte(ScrollBarPos), ObjektYScrollbar).SetYPos(0)
            If ClearLastDirectories And MovedBackward Then
                LastDirectories.Clear()
                MovedBackward = False
            ElseIf Not MovedBackward Then
                LastDirectories.Push(Folder)
            End If
        End If
    End Sub
    ''' <summary>
    ''' Dieses Item ist ausgewaehlt.
    ''' </summary>
    ''' <param name="Pos"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Shared Function GetSelectedItem(ByVal Pos As Point) As Integer
        Dim Rec As New Rectangle(Dimension.X + 15, Dimension.Y + 55, Dimension.Width - 15 - 35, Dimension.Height - 120)
        If Rec.Contains(Pos) Then
            CurrentSelectedFolder = Math.DivRem((Pos.Y - Dimension.Y - 55), FontDimension.Height, 0)
            If CurrentSelectedFolder >= MaxShownItems Or CurrentSelectedFolder >= CurrentFiles.Count Then
                CurrentSelectedFolder = -1
            End If
        Else
            CurrentSelectedFolder = -1
        End If
    End Function
    Private Shared Sub ChangeCurrentFile(ByVal File As String)
        If My.Computer.FileSystem.FileExists(File) Then
            CurrentFile = File
            CType(Objekte(CurrentFileTextbox), ObjektTextbox).SetText(CurrentFile.Replace(CurrentFolder, ""))
        End If
    End Sub
#End Region
#Region "ColorDialogue"
    ''' <summary>
    ''' Die momentan erstellte Farbe.
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared CurrentColor As Color
    ''' <summary>
    ''' Die Farbenauswahltextur.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared ColorTexture As Texture
    ''' <summary>
    ''' Ab hier stehen die 6 NUDS.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared NUDStart As Integer = -1
    ''' <summary>
    ''' Die Farbenauswahltextur.
    ''' </summary>
    ''' <remarks></remarks>
    Private Shared ColorCursorTexture(1) As Texture
    Private Shared BlueLine As Texture
    ''' <summary>
    ''' Zeigt den Farbdialog an.
    ''' </summary>
    ''' <param name="Title"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function ShowColorDialogue(ByVal Title As String, ByVal StartColor As Color) As MsgBoxResult
        Modus = Modi.ColorDialog
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Cancel
        GetResult = False
        CurrentFileTextbox = -1
        ColorTexture = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogue.png")
        ColorCursorTexture(0) = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogueCursor1.png")
        ColorCursorTexture(1) = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogueCursor2.png")
        'Dimension bestimmen.
        Dimension = New Rectangle(DataSettings.BildschirmBreite / 3, DataSettings.BildschirmHoehe / 4, 285, 370)
        If Dimension.X + Dimension.Width > DataSettings.BildschirmBreite Then
            Dimension.X = 0
        End If
        If Dimension.Y + Dimension.Height > DataSettings.BildschirmHoehe Then
            Dimension.Y = 0
        End If
        FontID = Schriftengine.CreateSchriftart(Schriftengine.Schriftarten.Courier_New, 10, FontStyle.Regular)
        FontDimension = Schriftengine.Fonts(FontID).GetFont.MeasureString(Schriftengine.MeasureSprite, "A", Microsoft.DirectX.Direct3D.DrawTextFormat.None, Color.Black).Size

        'Headline
        Dim Headline As String = ""
        If Title IsNot Nothing Then Headline = Title.ToString
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Headline}, New Point(0, 0), 10, 0, New PointF))
        Objekte(0).Rechteck = New Rectangle(Objekte(0).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

        Objekte.Add(New ObjektButton(Dimension.X + Dimension.Width - 120, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
        Objekte.Add(New ObjektButton(Dimension.X + 10, Dimension.Y + Dimension.Height - 30, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))

        'Numeric Up Down
        'RGB
        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + 60, Dimension.Y + Dimension.Height - 90), 1, New PointF))
        NUDStart = Objekte.Count - 1
        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + Dimension.Width - 60, Dimension.Y + Dimension.Height - 90), 1, New PointF))
        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + Dimension.Width - 60, Dimension.Y + Dimension.Height - 60), 1, New PointF))
        'Labels

        Objekte.Add(New ObjektLabel(Dimension.X + 10, Dimension.Y + Dimension.Height - 90, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rot")}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(Dimension.X + 10 + 60 + 60, Dimension.Y + Dimension.Height - 90, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Gruen")}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(Dimension.X + 10 + 60 + 60, Dimension.Y + Dimension.Height - 60, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Blau")}, New Point(0, 0), 10, 0, New PointF))

        ChangeCurrentColor(StartColor)

        Updateframe()

        Return MessageBox.Result
    End Function

    Private Shared Sub ChangeCurrentColor(ByVal Color As Color)
        CurrentColor = Color
        CType(Objekte(NUDStart), ObjektNumericUpDown).SetValue(CurrentColor.R)
        CType(Objekte(NUDStart + 1), ObjektNumericUpDown).SetValue(CurrentColor.G)
        CType(Objekte(NUDStart + 2), ObjektNumericUpDown).SetValue(CurrentColor.B)
        CreateBlueTexture()


        ' CType(Objekte(NUDStart),ObjektNumericUpDown).SetValue(CurrentColor.
    End Sub

    Private Shared Sub CreateBlueTexture()
        Dim B As New Bitmap(10, 256, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        For Y = 0 To 255
            For X = 0 To 9
                B.SetPixel(X, Y, Color.FromArgb(255, CurrentColor.R, CurrentColor.G, 255 - Y))
            Next
        Next
        BlueLine = Grafikengine.LoadTexture(B)
    End Sub
#End Region
#Region "Editor Box"
    Public Shared Output As New List(Of Object)
    Public Shared Unit As ObjektEinheit
    Public Shared Function ShowBoxChangeUnit(ByVal X As Integer, ByVal Y As Integer) As MsgBoxResult
        If Objektverwalter.Spielfeld.OnMap(X, Y) Then
            If Not Objektverwalter.Spielfeld.Einheiten(X, Y, Objektverwalter.Spielfeld.MomentaneSchlacht) Is Nothing Then
                Modus = Modi.MessageBox
                MessageDialogueBox = New MessageBox
                Result = MsgBoxResult.Abort
                GetResult = False

                Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 150
                Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 72
                Dimension = New Rectangle(X1, Y1, 300, 145)

                Dim E As ObjektEinheit = Objektverwalter.Spielfeld.Einheiten(X, Y, Objektverwalter.Spielfeld.MomentaneSchlacht)

                Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Einheit veraendern", New PointF))
                Objekte.Add(New ObjektButton(X1 + 180, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
                Objekte.Add(New ObjektNumericUpDown(E.Spieler, 1, Objektverwalter.Spielfeld.Spieler.Length - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 30), 1, New PointF))
                Objekte.Add(New ObjektNumericUpDown(E.getKP, 1, 10, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 50), 1, New PointF))
                If E.MunitionMax > 0 Then
                    Objekte.Add(New ObjektNumericUpDown(E.Munition, 0, E.MunitionMax, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 70), 1, New PointF))
                Else
                    Objekte.Add(New ObjektNumericUpDown(-1, -1, -1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 70), 1, New PointF))
                End If
                Objekte.Add(New ObjektNumericUpDown(E.Treibstoff, 0, E.SpritMax, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 90), 1, New PointF))
                Objekte.Add(New ObjektNumericUpDown(E.Rotation * 360 / (Math.PI * 2), 0, 360, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 185, Y1 + 50), 1, New PointF))
                Objekte.Add(New ObjektStringUpDown(E.EinheitenStufe, [Enum].GetNames(ObjektEinheit.Stufe.General.GetType), DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 185, Y1 + 25), New PointF()))
                Objekte.Add(New ObjektStringUpDown(E.AIUse, [Enum].GetNames(ObjektEinheit.AISetting.Standard.GetType), DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 185, Y1 + 70), New PointF()))
                'Label
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Spieler") + ":"}, New Point(0, 0), 10, 0, New PointF()))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Leben") + ":"}, New Point(0, 0), 10, 0, New PointF()))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Munition") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 90, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Treibstoff") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 130, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rang") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 130, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rotation") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 130, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("KI") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 25, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate(E.Einheitenname) + " X: " + E.X.ToString + " Y: " + E.Y.ToString}, New Point(0, 0), 10, 0, New PointF))


                Updateframe()

                Return MessageBox.Result
            End If
        End If
        Return MsgBoxResult.Abort
    End Function
    Public Shared Function ShowBoxChangeLoadedUnit(ByVal Unit As ObjektEinheit) As MsgBoxResult
        If Unit IsNot Nothing Then
            If Unit.Ladung.Length > 0 Then
                Modus = Modi.LoadUnit
                MessageDialogueBox = New MessageBox
                Result = MsgBoxResult.Abort
                GetResult = False

                Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 210
                Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 72
                Dimension = New Rectangle(X1, Y1, 420, 145)

                MessageBox.Unit = Unit

                Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Laden", New PointF))
                Objekte.Add(New ObjektButton(X1 + 150, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Entladen", New PointF))
                Objekte.Add(New ObjektButton(X1 + 300, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF))
                Dim List(Unit.GeladeneEinheitenIDs.Length - 1) As String
                For I = 0 To List.Length - 1
                    List(I) = ObjektLadeklasse.NewEinheit(Unit.GeladeneEinheitenIDs(I), 0, 0, 0).Einheitenname
                Next
                Dim E As ObjektEinheit
                If Unit.Ladung(0) IsNot Nothing Then
                    E = Unit.Ladung(0)
                    For I = 0 To Unit.GeladeneEinheitenIDs.Length - 1
                        If Unit.GeladeneEinheitenIDs(I) = E.EinheitenID Then
                            NUDStart = I
                            Exit For
                        End If
                    Next
                Else
                    E = ObjektLadeklasse.NewEinheit(Unit.GeladeneEinheitenIDs(0), Unit.Spieler, Unit.X, Unit.Y, False)
                    NUDStart = 0
                End If



                Objekte.Add(New ObjektStringUpDown(NUDStart, List, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 30), New PointF()))
                Objekte.Add(New ObjektNumericUpDown(E.getKP, 1, 10, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 50), 1, New PointF))
                If E.MunitionMax > 0 Then
                    Objekte.Add(New ObjektNumericUpDown(E.Munition, 0, E.MunitionMax, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 70), 1, New PointF))
                Else
                    Objekte.Add(New ObjektNumericUpDown(-1, -1, -1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 70), 1, New PointF))
                End If
                Objekte.Add(New ObjektNumericUpDown(E.Treibstoff, 0, E.SpritMax, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 90), 1, New PointF))
                Objekte.Add(New ObjektNumericUpDown(E.Rotation * 360 / (Math.PI * 2), 0, 360, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 315, Y1 + 50), 1, New PointF))
                Objekte.Add(New ObjektStringUpDown(E.EinheitenStufe, [Enum].GetNames(ObjektEinheit.Stufe.General.GetType), DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 315, Y1 + 25), New PointF()))
                Objekte.Add(New ObjektStringUpDown(E.AIUse, [Enum].GetNames(ObjektEinheit.AISetting.Standard.GetType), DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 315, Y1 + 70), New PointF()))
                'Label
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Einheit") + ":"}, New Point(0, 0), 10, 0, New PointF()))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Leben") + ":"}, New Point(0, 0), 10, 0, New PointF()))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Munition") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 90, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Treibstoff") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 260, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rang") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 260, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rotation") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 260, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("KI") + ":"}, New Point(0, 0), 10, 0, New PointF))
                Objekte.Add(New ObjektLabel(X1 + 25, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate(Unit.Einheitenname) + " X: " + Unit.X.ToString + " Y: " + Unit.Y.ToString + "  Loaded at:"}, New Point(0, 0), 10, 0, New PointF))
                Dim Max As Integer = 0
                For I = 1 To Unit.Ladung.Length
                    If Unit.Ladung(I - 1) Is Nothing Then

                        Exit For
                    End If
                    Max = I
                Next
                Objekte.Add(New ObjektNumericUpDown(1, 1, Max, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 270, Y1 + 10), 1, New PointF))
                CurrentFileTextbox = 1
                Updateframe()

                Return MessageBox.Result
            End If
        End If
        Return MsgBoxResult.Abort
    End Function
    Public Shared Function ShowBoxRandomMap() As MsgBoxResult
        Modus = Modi.MessageBox
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False

        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 250
        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 80
        Dimension = New Rectangle(X1, Y1, 500, 160)

        Objekte.Add(New ObjektButton(X1 + 10, Y1 + 130, DataSettings.Resourcenpfad + "Objects\Button.png", "Generieren", New PointF))
        Objekte.Add(New ObjektButton(X1 + 180, Y1 + 130, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
        'Zufallszhal
        Objekte.Add(New ObjektTextbox(X1 + 150, Y1 + 10, 120, New PointF))
        CType(Objekte(2), ObjektTextbox).SetText(Zufallszahl(0, Integer.MaxValue - 1).ToString)
        'Spieler
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Spieler.Length - 1, 2, 100, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 150, Y1 + 35), 1, New PointF(), 0))
        'Breite
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Breite, 3, 9999, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 150, Y1 + 60), 1, New PointF(), 0))
        'Hoehe
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Hoehe, 3, 9999, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 150, Y1 + 85), 1, New PointF(), 0))
        'Strassen?
        Objekte.Add(New ObjektCheckBox(New Point(X1 + 150, Y1 + 110), "CheckBox", New PointF, True))

        Objekte.Add(New ObjektMultiValue(0, 100, 5, New Point(X1 + 360, Y1 + 10), 100, 20, New PointF))
        CType(Objekte(7), ObjektMultiValue).SetValue(0, 65, False)
        CType(Objekte(7), ObjektMultiValue).SetValue(1, 12, False)
        CType(Objekte(7), ObjektMultiValue).SetValue(2, 8, False)
        CType(Objekte(7), ObjektMultiValue).SetValue(3, 5, False)
        CType(Objekte(7), ObjektMultiValue).SetValue(4, 10, False)



        'Label
        Objekte.Add(New ObjektLabel(X1 + 10, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Zufallszahl"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 10, Y1 + 35, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Spieler"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 10, Y1 + 60, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Breite"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 10, Y1 + 85, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Hoehe"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 10, Y1 + 110, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Strasse"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 300, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Ebene"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 300, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Wald"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 300, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Berg"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 300, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"See"}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(X1 + 300, Y1 + 90, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Stadt"}, New Point(0, 0), 10, 0, New PointF))


        '   Objekte.Add(New ObjektLabel(X1 + 130, Y1 + 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("KI") + ":"}, New Point(0, 0), 10, 0, New PointF))



        Updateframe()
        Return Result
    End Function
    Private Shared Sub UpdateUnit()
        Select Case Modus
            Case Modi.LoadUnit
                Dim CurPos As Integer = CType(Objekte(18), ObjektNumericUpDown).GetValue
                Dim CurUnit As Integer = CType(Objekte(3), ObjektStringUpDown).GetValueID
                If CurrentFileTextbox <> CurPos And Unit.Ladung(CurPos - 1) IsNot Nothing Then
                    Dim E As ObjektEinheit = Unit.Ladung(CurPos - 1)
                    CurrentFileTextbox = CurPos
                    For I = 0 To Unit.GeladeneEinheitenIDs.Length - 1
                        If Unit.GeladeneEinheitenIDs(I) = E.EinheitenID Then
                            NUDStart = I
                            Exit For
                        End If
                    Next
                    CType(Objekte(3), ObjektStringUpDown).SetValue(NUDStart)
                    CType(Objekte(4), ObjektNumericUpDown).SetValue(E.getKP)

                    If E.MunitionMax > 0 Then
                        CType(Objekte(5), ObjektNumericUpDown).SetMinimum(0)
                        CType(Objekte(5), ObjektNumericUpDown).SetMaximum(E.MunitionMax)
                        CType(Objekte(5), ObjektNumericUpDown).SetValue(E.Munition)
                    Else
                        CType(Objekte(5), ObjektNumericUpDown).SetMinimum(-1)
                        CType(Objekte(5), ObjektNumericUpDown).SetMaximum(-1)
                        CType(Objekte(5), ObjektNumericUpDown).SetValue(-1)
                    End If
                    If E.SpritMax < 0 Then
                        CType(Objekte(6), ObjektNumericUpDown).SetMinimum(-1)
                        CType(Objekte(6), ObjektNumericUpDown).SetMaximum(-1)
                    Else
                        CType(Objekte(6), ObjektNumericUpDown).SetMinimum(0)
                        CType(Objekte(6), ObjektNumericUpDown).SetMaximum(E.SpritMax)
                    End If
                    CType(Objekte(6), ObjektNumericUpDown).SetValue(E.Treibstoff)
                    CType(Objekte(7), ObjektNumericUpDown).SetValue(E.Rotation * 360)
                    CType(Objekte(8), ObjektStringUpDown).SetValue(E.EinheitenStufe)
                    CType(Objekte(9), ObjektStringUpDown).SetValue(E.AIUse)
                ElseIf CurUnit <> NUDStart Then
                    NUDStart = CurUnit
                    Dim E As ObjektEinheit = ObjektLadeklasse.NewEinheit(Unit.GeladeneEinheitenIDs(CurUnit), Unit.Spieler, Unit.X, Unit.Y, False)
                    CType(Objekte(4), ObjektNumericUpDown).SetValue(E.getKP)
                    If E.MunitionMax > 0 Then
                        CType(Objekte(5), ObjektNumericUpDown).SetMinimum(0)
                        CType(Objekte(5), ObjektNumericUpDown).SetMaximum(E.MunitionMax)
                        CType(Objekte(5), ObjektNumericUpDown).SetValue(E.Munition)
                    Else
                        CType(Objekte(5), ObjektNumericUpDown).SetMinimum(-1)
                        CType(Objekte(5), ObjektNumericUpDown).SetMaximum(-1)
                        CType(Objekte(5), ObjektNumericUpDown).SetValue(-1)
                    End If
                    If E.SpritMax < 0 Then
                        CType(Objekte(6), ObjektNumericUpDown).SetMinimum(-1)
                        CType(Objekte(6), ObjektNumericUpDown).SetMaximum(-1)
                    Else
                        CType(Objekte(6), ObjektNumericUpDown).SetMinimum(0)
                        CType(Objekte(6), ObjektNumericUpDown).SetMaximum(E.SpritMax)
                    End If
                    CType(Objekte(6), ObjektNumericUpDown).SetValue(E.Treibstoff)
                    CType(Objekte(7), ObjektNumericUpDown).SetValue(E.Rotation * 360)
                    CType(Objekte(8), ObjektStringUpDown).SetValue(E.EinheitenStufe)
                    CType(Objekte(9), ObjektStringUpDown).SetValue(E.AIUse)
                End If
        End Select
    End Sub

    Public Shared Function ShowSetMapSettings() As MsgBoxResult
        Modus = Modi.MessageBox
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False

        Dimension = New Rectangle(0, 0, DataSettings.BildschirmBreite, DataSettings.BildschirmHoehe)


        Dim P As New ObjektPanel2D(New Rectangle(5, 5, DataSettings.BildschirmBreite - 10, DataSettings.BildschirmHoehe - 10), New PointF, 3, False)
        Objekte.Add(New ObjektButton(10, DataSettings.BildschirmHoehe - 40, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF(), P))
        Objekte.Add(New ObjektButton(10 + 130, DataSettings.BildschirmHoehe - 40, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF(), P))
        Objekte.Add(New ObjektLabel(5, 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Sprachconverter.Translate("Karteneinstellungen")}, New Point(0, 0), 10, 0, New PointF, ))
        Objekte(Objekte.Count - 1).Rechteck = New Rectangle(Objekte(Objekte.Count - 1).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

        'Kartenname
        Objekte.Add(New ObjektLabel(5, 40, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Kartenname")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektTextbox(Dimension.X + 100, 40, Dimension.Width - 20 - 115, New PointF, P))
        CType(Objekte(Objekte.Count - 1), ObjektTextbox).SetText(Objektverwalter.Spielfeld.Kartenname)
        'Kartenbeschreibung
        Objekte.Add(New ObjektLabel(5, 70, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Beschreibung")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektTextbox(Dimension.X + 100, 70, Dimension.Width - 20 - 115, New PointF, P))
        CType(Objekte(Objekte.Count - 1), ObjektTextbox).SetText(Objektverwalter.Spielfeld.Beschreibung)
        'Autor
        Objekte.Add(New ObjektLabel(5, 100, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Autor")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektTextbox(Dimension.X + 100, 100, Dimension.Width - 20 - 115, New PointF, P))
        CType(Objekte(Objekte.Count - 1), ObjektTextbox).SetText(Objektverwalter.Spielfeld.Autor)
        'Startrechteck
        Objekte.Add(New ObjektLabel(5, 130, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rechts")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.StartRechteck.X, 0, Objektverwalter.Spielfeld.Breite - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(100, 130), 1, New PointF, , P))
        Objekte.Add(New ObjektLabel(240, 130, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Oben")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.StartRechteck.Y, 0, Objektverwalter.Spielfeld.Hoehe - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(340, 130), 1, New PointF, , P))
        Objekte.Add(New ObjektLabel(5, 160, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Links")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.StartRechteck.X, 0, Objektverwalter.Spielfeld.Breite - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(100, 160), 1, New PointF, , P))
        Objekte.Add(New ObjektLabel(240, 160, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Unten")}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.StartRechteck.Y, 0, Objektverwalter.Spielfeld.Hoehe - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(340, 160), 1, New PointF, , P))

        'Wetter
        'Sonne
        Objekte.Add(New ObjektLabel(5, 190, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Sonne"}, New Point, 10, 0, New PointF(), P))
        'Regen
        Objekte.Add(New ObjektLabel(5, 210, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Regen"}, New Point, 10, 0, New PointF(), P))
        'Schnee
        Objekte.Add(New ObjektLabel(5, 230, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Schnee"}, New Point, 10, 0, New PointF(), P))
        'Sandsturm
        Objekte.Add(New ObjektLabel(5, 250, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Sandsturm"}, New Point, 10, 0, New PointF(), P))
        'Der Multivalue fuer das Wetter wird erschaffen
        Objekte.Add(New ObjektMultiValue(0, 100, 4, New Point(100, 190), 100, 20, New PointF, P))
        'Die Values erhalten die Standardwerte der Karte
        For I = 0 To 3
            CType(Objekte(Objekte.Count - 1), ObjektMultiValue).SetValue(I, Objektverwalter.Spielfeld.Regeln.Wetterwahrscheinlichkeiten(I), False)
        Next
        'Kriegsnebel
        Objekte.Add(New ObjektLabel(240, 190, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Kriegsnebel"}, New Point, 10, 0, New PointF(), P))
        Objekte.Add(New ObjektStringUpDown(Objektverwalter.Spielfeld.Regeln.Nebel, [Enum].GetNames(Nebelarten.Aus.GetType), DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(350, 190), New PointF(), P))
        'CheckBox Luftschlacht
        Objekte.Add(New ObjektLabel(240, 210, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Luftschlacht"}, New Point, 10, 0, New PointF(), P))
        Objekte.Add(New ObjektCheckBox(New Point(350, 210), "CheckBox", New PointF, Objektverwalter.Spielfeld.Regeln.Luftschlacht, P))
        'Rang
        Objekte.Add(New ObjektLabel(240, 230, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Rang System"}, New Point, 10, 0, New PointF(), P))
        Objekte.Add(New ObjektCheckBox(New Point(350, 230), "CheckBox", New PointF, Objektverwalter.Spielfeld.Regeln.LevelModus, P))
        'Standardwetter
        Objekte.Add(New ObjektLabel(240, 250, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Standardwetter"}, New Point, 10, 0, New PointF(), P))
        Objekte.Add(New ObjektDropDownMenue(350, 250, [Enum].GetNames(ObjektSpielfeld.Wetterarten.Regen.GetType), New PointF, , P))
        CType(Objekte(Objekte.Count - 1), ObjektDropDownMenue).SetItem(Objektverwalter.Spielfeld.Regeln.Standardwetter)
        'Zufallswetter?
        Objekte.Add(New ObjektLabel(240, 270, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Zufallswetter"}, New Point, 10, 0, New PointF(), P))
        Objekte.Add(New ObjektCheckBox(New Point(350, 270), "CheckBox", New PointF, Objektverwalter.Spielfeld.Regeln.Zufallswetter, P))

        Objekte.Add(P)
        Updateframe()

        Return MessageBox.Result
    End Function
    Public Shared Function ShowNewMap(ByVal NewMap As Boolean) As MsgBoxResult
        Modus = Modi.MessageBox
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False

        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 150
        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 72
        Dimension = New Rectangle(X1, Y1, 300, 145)
        If NewMap Then
            Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Neue Karte", New PointF()))
            Objekte.Add(New ObjektButton(X1 + 180, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF()))
        Else
            Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Karte veraendern", New PointF()))
            Objekte.Add(New ObjektButton(X1 + 180, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF()))
        End If
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Spieler.Length - 1, 2, 99, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 10), 1, New PointF()))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Breite, 1, 9999, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 30), 1, New PointF()))
        Objekte.Add(New ObjektNumericUpDown(Objektverwalter.Spielfeld.Hoehe, 1, 9999, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 50), 1, New PointF()))
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Spieler"}, New Point(0, 0), 10, 0, New PointF()))
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Breite"}, New Point(0, 0), 10, 0, New PointF()))
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 50, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Hoehe"}, New Point(0, 0), 10, 0, New PointF()))

        Updateframe()

        Return MessageBox.Result
    End Function
    Shared EditedPlayer As Integer
    Public Shared Function ShowEditPlayer(ByVal CurrentPlayer As Integer) As MsgBoxResult
        Modus = Modi.SpielerAendern
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Ok
        GetResult = False

        Dimension = New Rectangle(0, 0, DataSettings.BildschirmBreite, DataSettings.BildschirmHoehe)
        Dim X1 As Integer = 15
        Dim Y1 As Integer = 15

        Dim P As New ObjektPanel2D(New Rectangle(5, 5, DataSettings.BildschirmBreite - 10, DataSettings.BildschirmHoehe - 10), New PointF, 3, False)
        Objekte.Add(New ObjektButton(10, DataSettings.BildschirmHoehe - 40, DataSettings.Resourcenpfad + "Objects\Button.png", "Ok", New PointF(), P))
        Objekte.Add(New ObjektButton(10, DataSettings.BildschirmHoehe - 80, DataSettings.Resourcenpfad + "Objects\Button.png", "Aendern", New PointF(), P))

        Objekte.Add(New ObjektLabel(5, 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Sprachconverter.Translate("Spieler")}, New Point(0, 0), 10, 0, New PointF, ))
        Objekte(Objekte.Count - 1).Rechteck = New Rectangle(Objekte(Objekte.Count - 1).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))
        'Player to Edit.
        Objekte.Add(New ObjektNumericUpDown(CurrentPlayer, 1, Objektverwalter.Spielfeld.Spieler.Length - 1, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(X1 + 80, Y1 + 10), 1, New PointF(), , P))
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 10, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"Spieler"}, New Point(0, 0), 10, 0, New PointF(), P))


        'Numeric Up Down
        'RGB
        CurrentFileTextbox = -1
        ColorTexture = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogue.png")
        ColorCursorTexture(0) = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogueCursor1.png")
        ColorCursorTexture(1) = Grafikengine.LoadTexture(DataSettings.Resourcenpfad + "Objects\ColorDialogueCursor2.png")

        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + 60, Dimension.Y + 320), 1, New PointF))
        NUDStart = Objekte.Count - 1
        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + 180, Dimension.Y + 320), 1, New PointF))
        Objekte.Add(New ObjektNumericUpDown(0, 0, 255, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(Dimension.X + 180, Dimension.Y + 360), 1, New PointF))
        'Labels

        Objekte.Add(New ObjektLabel(Dimension.X + 10, Dimension.Y + 320, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Rot")}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(Dimension.X + 10 + 60 + 60, Dimension.Y + 320, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Gruen")}, New Point(0, 0), 10, 0, New PointF))
        Objekte.Add(New ObjektLabel(Dimension.X + 10 + 60 + 60, Dimension.Y + +360, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Blau")}, New Point(0, 0), 10, 0, New PointF))

        'Income
        Objekte.Add(New ObjektNumericUpDown(1000, 500, 99500, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(80, 380), 500, New PointF, , P))
        Objekte.Add(New ObjektLabel(10, 385, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Einkommen") + ":"}, New Point(0, 0), 10, 0, New PointF))
        'Startfonds
        Objekte.Add(New ObjektLabel(170, 385, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Fonds") + ":"}, New Point(0, 0), 10, 0, New PointF, P))
        Objekte.Add(New ObjektNumericUpDown(0, 0, 99500, DataSettings.Resourcenpfad + "Objects\NUD.png", New Point(240, 380), 500, New PointF, , P))
        'Team
        Objekte.Add(New ObjektDropDownMenue(80, 405, [Enum].GetNames(Objektverwalter.ABC.A.GetType), New PointF, , P))
        Objekte.Add(New ObjektLabel(10, 410, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("Team") + ":"}, New Point(0, 0), 10, 0, New PointF, P))
        'KI
        Dim Werte() As String = [Enum].GetNames(ObjektSpieler.KIStufen.Mensch.GetType)
        Array.Resize(Werte, Werte.Length - 2)
        Objekte.Add(New ObjektDropDownMenue(240, 405, Werte, New PointF, , P))
        Objekte.Add(New ObjektLabel(170, 410, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {"KI Staerke"}, New Point(0, 0), 10, 0, New PointF, P))

        Objekte.Add(P)

        ChangeCurrentPlayer(CurrentPlayer)


        Updateframe()

        Return MessageBox.Result
    End Function

    Private Shared Sub ChangeCurrentPlayer(ByVal CurrentPlayer As Integer)
        ChangeCurrentColor(Objektverwalter.Spielfeld.Spieler(CurrentPlayer).Farbe)
        CType(Objekte(11), ObjektNumericUpDown).SetValue(Objektverwalter.Spielfeld.Spieler(CurrentPlayer).FondsproStadt)
        CType(Objekte(14), ObjektNumericUpDown).SetValue(Objektverwalter.Spielfeld.Spieler(CurrentPlayer).Fonds)
        CType(Objekte(15), ObjektDropDownMenue).SetItem(Objektverwalter.Spielfeld.Spieler(CurrentPlayer).Team)
        CType(Objekte(17), ObjektDropDownMenue).SetItem(Objektverwalter.Spielfeld.Spieler(CurrentPlayer).KIStufe)
        EditedPlayer = CurrentPlayer
    End Sub

#End Region
#Region "Network"
    Public Shared Function ShowEnterIP() As MsgBoxResult
        Modus = Modi.MessageBox
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False

        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 150
        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 72
        Dimension = New Rectangle(X1, Y1, 300, 145)
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {"Verbinden mit"}, New Point(0, 0), 10, 0, New PointF))
        Objekte(0).Rechteck = New Rectangle(Objekte(0).Rechteck.Location, New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))

        Objekte.Add(New ObjektButton(X1 + 10, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Verbinden", New PointF))
        Objekte.Add(New ObjektButton(X1 + 180, Y1 + 115, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
        'Label
        Objekte.Add(New ObjektLabel(X1 + 15, Y1 + 30, DataSettings.Resourcenpfad + "Objects\Transparent.png", New String() {Sprachconverter.Translate("TCP\IP") + ":"}, New Point(0, 0), 10, 0, New PointF()))
        Objekte.Add(New ObjektTextbox(Dimension.X + 60, Dimension.Y + 30, Dimension.Width - 20 - 60, New PointF))

        Updateframe()

        Return MessageBox.Result
    End Function
    Public Shared Function ShowWaitBox(ByVal Message As String) As MsgBoxResult
        Modus = Modi.ConnectToHost
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Sprachconverter.Translate(Message) + "..."}, New Point(0, 0), 10, 0, New PointF))
        Dim W As Integer
        Schriftengine.MeasureSpriteLocker.Lock()
        W = CType(Objekte(0), ObjektLabel).Text.GetSchriftart.MeasureString(Schriftengine.MeasureSprite, Sprachconverter.Translate(Message) + "...", DrawTextFormat.None, Color.Black).Width + 10
        Schriftengine.MeasureSpriteLocker.Unlock()
        If W < 120 Then W = 120
        If W > DataSettings.BildschirmBreite Then W = DataSettings.BildschirmBreite
        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - W / 2

        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 25
        Dimension = New Rectangle(X1, Y1, W, 50)


        Objekte(0).Rechteck = New Rectangle(New Point(Dimension.X + 5, Dimension.Y + 5), New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))
        Objekte(0).Koordinaten = New Point(Dimension.X + 5, Dimension.Y + 5)
        Objekte.Add(New ObjektButton(X1 + 6, Y1 + 22, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
        Updateframe()

        Return MessageBox.Result
    End Function
#End Region
#Region "Keymenue"
    Public Shared CurrentKey As Keys = -1
    Public Shared Function ShowKeyInput() As MsgBoxResult
        CurrentKey = -1

        Modus = Modi.KeyInput
        MessageDialogueBox = New MessageBox
        Result = MsgBoxResult.Abort
        GetResult = False
        Objekte.Add(New ObjektLabel(Dimension.X + 5, Dimension.Y + 5, DataSettings.Resourcenpfad + "Objects\Blaugrau.png", New String() {Sprachconverter.Translate("Druecke eine Taste")}, New Point(0, 0), 10, 0, New PointF))

        Dim X1 As Integer = DataSettings.BildschirmBreite / 2 - 120 / 2

        Dim Y1 As Integer = DataSettings.BildschirmHoehe / 2 - 25
        Dimension = New Rectangle(X1, Y1, 120, 50)


        Objekte(0).Rechteck = New Rectangle(New Point(Dimension.X + 5, Dimension.Y + 5), New Size(Dimension.Width - 10, Objekte(0).Rechteck.Height))
        Objekte(0).Koordinaten = New Point(Dimension.X + 5, Dimension.Y + 5)
        Objekte.Add(New ObjektButton(X1 + 6, Y1 + 22, DataSettings.Resourcenpfad + "Objects\Button.png", "Abbrechen", New PointF))
        Updateframe()

        Return MessageBox.Result
    End Function

#End Region

#Region "Input Output"
    ''' <summary>
    ''' Updateframe fuers Malen...
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Sub Updateframe()
        Output.Clear()
        Dim CursorStatus As Boolean = ObjektMaus.Visible
        While Not GetResult
            ObjektMaus.Visible = True
            'Frames per Second
            While VideoKlasse.Beschaeftigt Or Hauptmenue.PauseFuerObjekteLaden
                Threading.Thread.Sleep(100)
            End While
            If Hauptmenue.MusikAnhalten = True Then
                MusikEngine.MusikStop()
                Hauptmenue.MusikAnhalten = False
            End If
            If MusikEngine.MusikStopped Or MusikEngine.MusikEnded Then
                Hauptmenue.MusikZufaellig()
            End If

            Dim Ticks As Long = Now.Ticks
            Dim FT2 As Long = Hauptmenue.FrameTicks + CLng(TimeSpan.TicksPerSecond / DataSettings.SpielGeschwindigkeit)
            If FT2 > Ticks Then
                'Wir fuehren alles in der momentanen Schleife aus
                My.Application.DoEvents()
                'Jetzt sollte kein Esc problem auftreten.
                Continue While
            Else
                Hauptmenue.FrameTicks = Now.Ticks
            End If

            'Cursor Update
            If Objektverwalter.Menue IsNot Nothing Then
                Objektverwalter.Menue.SetMausBild()
            End If

            'FPS errechnen
            If Hauptmenue.FPSS = Now.Second Then
                Hauptmenue.FPSN += 1
            Else
                Hauptmenue.FPS = Hauptmenue.FPSN
                Hauptmenue.FPSN = 0
                Hauptmenue.FPSS = Now.Second
            End If

            ObjektMaus.Zustand = ObjektMaus.Zustaende.Menue

            'Musikengine Wav Update
            MusikEngine.FrameMusik()
            'Objektframes
            If Not Objektverwalter.Menue Is Nothing Then Objektverwalter.Menue.Frame()
            Hauptmenue.Frame += 1


            'Updates vor dem naechsten Malen
            If Hauptmenue.Frame >= 3 Then
                Hauptmenue.Frame = 0
                Hauptmenue.FramesAktualisieren()
            End If
            'Delete the current Tooltip.
            Objektverwalter.ToolTips = Nothing

            'Wir zeichnen das neue Bild
            If Grafikengine.Updateframe = False Then
                Hauptmenue.Engineladen()
            End If

            My.Application.DoEvents()
        End While
        ObjektMaus.Visible = CursorStatus
        CloseBoxDialogue()
    End Sub
    ''' <summary>
    ''' Closes the Dialogue Box
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Sub CloseBoxDialogue()
        MessageDialogueBox = Nothing
        Modus = -1
        For Each Obj In Objekte
            If TypeOf Obj Is ObjektDropDownMenue Then
                Output.Add(CType(Obj, ObjektDropDownMenue).GetItem)
            ElseIf TypeOf Obj Is ObjektNumericUpDown Then
                Output.Add(CType(Obj, ObjektNumericUpDown).GetValue)
            ElseIf TypeOf Obj Is ObjektTextbox Then
                Output.Add(CType(Obj, ObjektTextbox).GetText)
            ElseIf TypeOf Obj Is ObjektStringUpDown Then
                Output.Add(CType(Obj, ObjektStringUpDown).GetValue)
            ElseIf TypeOf Obj Is ObjektMultiValue Then
                Dim Values As New List(Of Integer)
                Dim Mult As ObjektMultiValue = Obj
                For I = 0 To Mult.Values.Length - 1
                    Values.Add(Mult.GetValue(I))
                Next
                Output.Add(Values)
            ElseIf TypeOf Obj Is ObjektCheckBox Then
                Output.Add(CType(Obj, ObjektCheckBox).Checked)
            End If
            Objekt2D.RemoveObjekt(Obj)
        Next
        LastDirectories.Clear()
        CurrentFiles.Clear()
        Objekte.Clear()
        If ColorTexture IsNot Nothing Then
            ColorTexture.Dispose()
            ColorTexture = Nothing
            ColorCursorTexture(0).Dispose()
            ColorCursorTexture(1).Dispose()
            ColorCursorTexture(0) = Nothing
            ColorCursorTexture(1) = Nothing
        End If
        GetResult = True
    End Sub
    ''' <summary>
    ''' Draws the Dialogue to Screen.
    ''' </summary>
    ''' <remarks></remarks>
    Public Shared Sub Draw()
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(180, 255, 255, 255)
        Grafikengine.DrawBox(TexturenHalter.GetBoxHintergrund(0), Dimension.Location, New Size(144, 145), Dimension.Size, 5, intColor)
        Select Case Modus
            Case Modi.LoadUnit
                UpdateUnit()
            Case Modi.ConnectToHost
                If Hauptmenue.Connection.Connected Then
                    Result = MsgBoxResult.Yes
                    GetResult = True
                End If
            Case Modi.MessageBox
            Case Modi.ColorDialog
                Dim R As Integer = CType(Objekte(NUDStart), ObjektNumericUpDown).GetValue
                Dim G As Integer = CType(Objekte(NUDStart + 1), ObjektNumericUpDown).GetValue
                Dim B As Integer = CType(Objekte(NUDStart + 2), ObjektNumericUpDown).GetValue
                If R <> CurrentColor.R Or B <> CurrentColor.B Or G <> CurrentColor.G Then
                    ChangeCurrentColor(Color.FromArgb(255, R, G, B))
                End If
                Grafikengine.Draw2D(ColorTexture, Dimension.Location + New Point(5, 20), New Rectangle(0, 0, 256, 256), New Point, 0, Color.White)
                Grafikengine.Draw2D(BlueLine, Dimension.Location + New Point(265, 20), New Rectangle(0, 0, 10, 256), New Point, 0, Color.White)
                Grafikengine.fillRect(New Rectangle(Dimension.Location + New Point(20, 305), New Size(30, 30)), CurrentColor)
                'Cursor malen
                Grafikengine.Draw2D(ColorCursorTexture(0), Dimension.Location + New Point(5 + CurrentColor.R, 20 + CurrentColor.G), New Rectangle(0, 0, 19, 19), New Point(10, 10), 0, Color.White)
                Grafikengine.Draw2D(ColorCursorTexture(1), Dimension.Location + New Point(265 + 5, 20 + 255 - CurrentColor.B), New Rectangle(0, 0, 6, 11), New Point(0, 6), 0, Color.White)
            Case Modi.SpielerAendern
                Dim R As Integer = CType(Objekte(NUDStart), ObjektNumericUpDown).GetValue
                Dim G As Integer = CType(Objekte(NUDStart + 1), ObjektNumericUpDown).GetValue
                Dim B As Integer = CType(Objekte(NUDStart + 2), ObjektNumericUpDown).GetValue
                If R <> CurrentColor.R Or B <> CurrentColor.B Or G <> CurrentColor.G Then
                    ChangeCurrentColor(Color.FromArgb(255, R, G, B))
                End If
                Grafikengine.Draw2D(ColorTexture, Dimension.Location + New Point(10, 60), New Rectangle(0, 0, 256, 256), New Point, 0, Color.White)
                Grafikengine.Draw2D(BlueLine, Dimension.Location + New Point(280, 60), New Rectangle(0, 0, 10, 256), New Point, 0, Color.White)
                Grafikengine.fillRect(New Rectangle(Dimension.Location + New Point(20, 350), New Size(30, 30)), CurrentColor)
                'Cursor malen
                Grafikengine.Draw2D(ColorCursorTexture(0), Dimension.Location + New Point(10 + CurrentColor.R, 60 + CurrentColor.G), New Rectangle(0, 0, 19, 19), New Point(10, 10), 0, Color.White)
                Grafikengine.Draw2D(ColorCursorTexture(1), Dimension.Location + New Point(280 + 5, 60 + 255 - CurrentColor.B), New Rectangle(0, 0, 6, 11), New Point(0, 6), 0, Color.White)
                Dim CPlayer As Integer = CType(Objekte(3), ObjektNumericUpDown).GetValue
                If EditedPlayer <> CPlayer Then
                    ChangeCurrentPlayer(CPlayer)
                End If
            Case Modi.OpenDialog, Modi.SaveDialog, Modi.OrdnerDialog
                If FilterBox >= 0 Then
                    Dim newFilter As String = CType(Objekte(FilterBox), ObjektDropDownMenue).GetItem
                    Dim NewFolder As String = CurrentFolder
                    If Objekte(CurrentFolderTextbox).Focused = False Then
                        NewFolder = CType(Objekte(CurrentFolderTextbox), ObjektTextbox).GetText
                    End If
                    If newFilter <> CurrentFilter Or NewFolder <> CurrentFolder Then
                        CurrentFilter = newFilter
                        ChangeCurrentFolder(NewFolder)
                    End If
                End If
                If CurrentFileTextbox >= 0 Then
                    CurrentFile = CType(Objekte(CurrentFileTextbox), ObjektTextbox).GetText
                End If
                Grafikengine.DrawBox(TexturenHalter.GetBoxHintergrund(0), Dimension.Location + New Point(10, 50), New Size(144, 145), Dimension.Size - New Size(10 + 10, 50 + 60), 5, intColor)
                'Dateien anzeigen.
                Dim Proz As Single = CType(Objekte(ScrollBarPos), ObjektYScrollbar).GetValuePos
                Dim AngezeigteDateien(MaxShownItems - 1) As String
                If AngezeigteDateien.Length > CurrentFiles.Count Then Array.Resize(AngezeigteDateien, CurrentFiles.Count)
                Dim AnzeigeStart As Integer = 0
                If CurrentFiles.Count > MaxShownItems Then
                    AnzeigeStart = (CurrentFiles.Count - MaxShownItems) * Proz
                End If

                If AnzeigeStart + MaxShownItems > CurrentFiles.Count Then AnzeigeStart = CurrentFiles.Count - MaxShownItems
                If AnzeigeStart < 0 Then AnzeigeStart = 0
                For I = AnzeigeStart To AnzeigeStart + MaxShownItems - 1
                    If I < CurrentFiles.Count Then
                        AngezeigteDateien(I - AnzeigeStart) = CurrentFiles(I).Replace(CurrentFolder, "")
                    Else
                        Exit For
                    End If
                Next
                Text.neuerText(AngezeigteDateien, Dimension.X + 15, Dimension.Y + 55, Nothing, , 0)
                Text.Malen(New Point)
                If CurrentSelectedFolder >= 0 Then
                    Dim Pos As New Point(Dimension.X + 15, Dimension.Y + 55 + FontDimension.Height * CurrentSelectedFolder)
                    Grafikengine.DrawBox(TexturenHalter.GetBoxHintergrund(2), Pos, New Size(112, 22), New Size(FontDimension.Width * AngezeigteDateien(CurrentSelectedFolder).Length, FontDimension.Height), 1, Color.White)
                End If
        End Select
        ObjekteLocker.Lock()
        For Each Objekt In Objekte
            If Not Objekt.Focused Then
                Objekt.Malen()
            End If
        Next

        For Each Obj In Objekte
            If Obj.Focused Then
                Obj.Malen()
            End If
        Next
        ObjekteLocker.Unlock()
    End Sub
    Public Shared Sub KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        For Each Obj In Objekte
            If Obj.Focused Then
                Obj.Keydown(sender, e)
                Exit Sub
            End If
        Next
        For Each Obj In Objekte
            If Not Obj.Focused Then
                Obj.Keydown(sender, e)
            End If
        Next
        Select Case Modus
            Case Modi.KeyInput
                Select Case e.KeyCode
                    Case Keys.Delete, Keys.Shift, Keys.Alt, Keys.ShiftKey, _
                         Keys.Control, Keys.ControlKey
                    Case Keys.Escape
                        GetResult = True 'Close the Box
                    Case Else
                        Result = MsgBoxResult.Ok
                        CurrentKey = e.KeyCode
                        CloseBoxDialogue()
                End Select
            Case Else
                Select Case e.KeyCode
                    Case Keys.Escape
                        GetResult = True 'Close the Box
                    Case Keys.Delete
                        Select Case Modus
                            Case Modi.OpenDialog, Modi.SaveDialog
                                Dim CFile As String = CurrentFile
                                Dim CurFile As String() = CurrentFile.Split("\")
                                Dim Params As String() = CurrentFilter.Split(";")
                                Dim Endung As String = Params(1).Replace("*", "")
                                If Not CurFile(CurFile.Length - 1).Contains(".") Then CFile += Endung
                                If Not CurFile(0).EndsWith(":") Then CFile = CurrentFolder + CFile
                                If My.Computer.FileSystem.FileExists(CFile) Then
                                    My.Computer.FileSystem.DeleteFile(CFile)
                                    CType(Objekte(CurrentFileTextbox), ObjektTextbox).SetText("")
                                    CurrentFile = ""
                                    ChangeCurrentFolder(CurrentFolder)
                                End If
                        End Select
                End Select
        End Select
       
    End Sub
    Public Shared Sub MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        For Each Obj In Objekte
            If Obj.Focused Then
                Obj.MouseDown(sender, e)
                Exit Sub
            End If
        Next
        For Each Obj In Objekte
            If Not Obj.Focused Then
                Obj.MouseDown(sender, e)
            End If
        Next
        If e.Clicks >= 2 Then
            Select Case Modus
                Case Modi.SaveDialog, Modi.OpenDialog
                    DoubleClick = True
            End Select
        End If
    End Sub
    Public Shared Sub MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        For Each Obj In Objekte
            If Obj.Focused Then
                Obj.MouseEnter(sender, e)
                Exit Sub
            End If
        Next
        For Each Obj In Objekte
            If Not Obj.Focused Then
                Obj.MouseEnter(sender, e)
            End If
        Next
        Select Case Modus
            Case Modi.OpenDialog, Modi.SaveDialog, Modi.OrdnerDialog
                GetSelectedItem(e.Location)
            Case Modi.ColorDialog

        End Select
    End Sub
    Public Shared Sub MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim Result As String = ""
        If Not Objekt2D.HasFocus Then
            If DoubleClick Then
                If CurrentFile <> "" Then
                    Select Case Modus
                        Case Modi.OpenDialog
                            Result = "oeffnen"
                        Case Modi.SaveDialog
                            Result = "speichern"
                    End Select
                End If
            End If
            Select Case Modus
                Case Modi.OpenDialog, Modi.SaveDialog, Modi.OrdnerDialog
                    If CurrentSelectedFolder >= 0 Then
                        Dim Proz As Single = CType(Objekte(ScrollBarPos), ObjektYScrollbar).GetValuePos
                        Dim AnzeigeStart As Integer = 0
                        If CurrentFiles.Count > MaxShownItems Then
                            AnzeigeStart = (CurrentFiles.Count - MaxShownItems) * Proz
                        End If

                        Dim File As String = CurrentFiles(AnzeigeStart + CurrentSelectedFolder)
                        If File = "." Then
                            If LastDirectories.Count > 0 Then
                                Dim NewPath As String = LastDirectories.Pop
                                If Not MovedBackward Then NewPath = LastDirectories.Pop
                                MovedBackward = True
                                ChangeCurrentFolder(NewPath, False)
                            End If
                            Result = ""
                        ElseIf File = ".." Then
                            Dim NewPath As String = CurrentFolder
                            If NewPath.EndsWith("\") Then NewPath = NewPath.Remove(NewPath.LastIndexOf("\"))
                            If NewPath.Contains("\") Then
                                NewPath = NewPath.Remove(NewPath.LastIndexOf("\"))
                            End If
                            ChangeCurrentFolder(NewPath + "\")
                            Result = ""
                        ElseIf My.Computer.FileSystem.DirectoryExists(File) Then
                            If File.EndsWith("\") Then
                                ChangeCurrentFolder(File)
                            Else
                                ChangeCurrentFolder(File + "\")
                            End If
                            Result = ""
                        Else
                            ChangeCurrentFile(File)
                        End If
                    End If
                Case Modi.ColorDialog
                    Dim Rec As New Rectangle(Dimension.Location.X + 5, Dimension.Location.Y + 20, 256, 256)
                    If Rec.Contains(e.Location) Then
                        Dim R As Integer = 0
                        If e.X <> Rec.X Then
                            R = (e.X - Rec.X) - 1
                        End If
                        Dim G As Integer = 0
                        If e.Y <> Rec.Y Then
                            G = (e.Y - Rec.Y) - 1
                        End If
                        ChangeCurrentColor(Color.FromArgb(255, R, G, CurrentColor.B))
                    End If
                    Rec = New Rectangle(Dimension.Location + New Point(265, 20), New Size(10, 256))
                    If Rec.Contains(e.Location) Then
                        Dim B As Integer = 255
                        If e.Y <> Rec.Y Then
                            B = 255 - ((e.Y - Rec.Y) - 1)
                        End If
                        ChangeCurrentColor(Color.FromArgb(255, CurrentColor.R, CurrentColor.G, B))
                    End If
                Case Modi.SpielerAendern
                    Dim Rec As New Rectangle(Dimension.Location.X + 10, Dimension.Location.Y + 60, 256, 256)
                    If Rec.Contains(e.Location) Then
                        Dim R As Integer = 0
                        If e.X <> Rec.X Then
                            R = (e.X - Rec.X) - 1
                        End If
                        Dim G As Integer = 0
                        If e.Y <> Rec.Y Then
                            G = (e.Y - Rec.Y) - 1
                        End If
                        ChangeCurrentColor(Color.FromArgb(255, R, G, CurrentColor.B))
                    End If
                    Rec = New Rectangle(Dimension.Location + New Point(280, 60), New Size(10, 256))
                    If Rec.Contains(e.Location) Then
                        Dim B As Integer = 255
                        If e.Y <> Rec.Y Then
                            B = 255 - ((e.Y - Rec.Y) - 1)
                        End If
                        ChangeCurrentColor(Color.FromArgb(255, CurrentColor.R, CurrentColor.G, B))
                    End If
            End Select
        End If
        For Each Obj In Objekte
            If Obj.Focused Then
                Result = Obj.MouseUp(sender, e)
                Exit For
            End If
        Next
        If Result = "" Then
            For Each Obj In Objekte
                If Not Obj.Focused Then
                    Result = Obj.MouseUp(sender, e)
                    If Result <> "" Then
                        Exit For
                    End If
                End If
            Next
        End If
        Select Case Result.ToLower
            Case "laden"
                Dim Pos As Integer = CType(Objekte(18), ObjektNumericUpDown).GetValue - 1

                Dim E1 As ObjektEinheit = ObjektLadeklasse.NewEinheit(Unit.GeladeneEinheitenIDs(NUDStart), Unit.Spieler, Unit.X, Unit.Y, True)
                E1.KP = CType(Objekte(4), ObjektNumericUpDown).GetValue * 10
                E1.Munition = CType(Objekte(5), ObjektNumericUpDown).GetValue

                E1.Treibstoff = CType(Objekte(6), ObjektNumericUpDown).GetValue
                E1.Rotation = CType(Objekte(7), ObjektNumericUpDown).GetValue
                E1.TruppenStufe = CType(Objekte(8), ObjektStringUpDown).GetValueID
                E1.AIUse = CType(Objekte(9), ObjektStringUpDown).GetValueID
                If Pos = 0 Then
                    Unit.Ladung(Pos) = E1
                ElseIf Unit.Ladung(Pos - 1) IsNot Nothing Then
                    Unit.Ladung(Pos) = E1
                Else
                    For I = 0 To Unit.Ladung.Length - 1
                        If Unit.Ladung(I) Is Nothing Then
                            Unit.Ladung(I) = E1
                            Exit For
                        End If
                    Next
                End If
                If Pos + 1 < Unit.Ladung.Length Then
                    CType(Objekte(18), ObjektNumericUpDown).SetMaximum(Pos + 2)
                End If
            Case "entladen"
                Dim Pos As Integer = CType(Objekte(18), ObjektNumericUpDown).GetValue - 1
                Unit.Ladung(Pos) = Nothing
                For I = Pos To Unit.Ladung.Length - 1
                    For I2 = I + 1 To Unit.Ladung.Length - 1
                        If Unit.Ladung(I2) IsNot Nothing Then
                            Unit.Ladung(I) = Unit.Ladung(I2)
                            Unit.Ladung(I2) = Nothing
                        End If
                    Next
                Next
                Dim Max As Integer = 0
                For I = 1 To Unit.Ladung.Length
                    If Unit.Ladung(I - 1) Is Nothing Then
                        Max = I
                        Exit For
                    End If
                Next
                CType(Objekte(18), ObjektNumericUpDown).SetMaximum(Max)
            Case "verbinden"
                MessageBox.Result = MsgBoxResult.Yes
                GetResult = True
            Case "ja"
                MessageBox.Result = MsgBoxResult.Yes
                GetResult = True
            Case "nein"
                MessageBox.Result = MsgBoxResult.No
                GetResult = True
            Case "ok"
                MessageBox.Result = MsgBoxResult.Ok
                GetResult = True
            Case "abbrechen"
                MessageBox.Result = MsgBoxResult.Cancel
                GetResult = True
            Case "generieren"
                MessageBox.Result = MsgBoxResult.Ok
                GetResult = True
            Case "oeffnen"
                Select Case Modus
                    Case Modi.OrdnerDialog
                        CurrentFile = CurrentFolder
                    Case Else
                        If Not My.Computer.FileSystem.FileExists(CurrentFile) Then
                            If Not My.Computer.FileSystem.FileExists(CurrentFolder + CurrentFile) Then
                                CurrentFile = ""
                            Else
                                CurrentFile = CurrentFolder + CurrentFile
                            End If
                        End If
                End Select
                MessageBox.Result = MsgBoxResult.Ok
                GetResult = True
            Case "speichern"
                Dim File As String = CurrentFile
                Dim Params As String() = CurrentFilter.Split(";")
                Dim Endung As String = Params(1).Replace("*", "")
                Dim CurFile As String() = CurrentFile.Split("\")
                If Not CurFile(CurFile.Length - 1).Contains(".") Then CurrentFile += Endung
                If Not CurFile(0).EndsWith(":") Then CurrentFile = CurrentFolder + CurrentFile
                If My.Computer.FileSystem.FileExists(CurrentFile) Then
                    Dim P As String = CurrentFolder
                    Dim Filter() As String = CType(Objekte(FilterBox), ObjektDropDownMenue).Items
                    Dim T As String = CType(Objekte(0), ObjektLabel).Text.Text(0)
                    For Each Obj In Objekte
                        Objekt2D.RemoveObjekt(Obj)
                    Next
                    Objekte.Clear()
                    If MessageBox.ShowMessageBox("Moechtest du die momentane Datei ueberschreiben?", MsgBoxStyle.YesNo, "Speichern") = MsgBoxResult.Yes Then
                        MessageBox.Result = MsgBoxResult.Ok
                        GetResult = True
                    Else
                        ShowOpenSaveDialogue(Modi.SaveDialog, T, P, Filter, File)
                    End If
                Else
                    MessageBox.Result = MsgBoxResult.Ok
                    GetResult = True
                End If
            Case "einheit veraendern", "karte veraendern", "neue karte"
                MessageBox.Result = MsgBoxResult.Ok
                GetResult = True
            Case "aendern"
                Dim CPlayer As Integer = CType(Objekte(3), ObjektNumericUpDown).GetValue
                Objektverwalter.Spielfeld.Spieler(CPlayer).Farbe = CurrentColor
                Objektverwalter.Spielfeld.Spieler(CPlayer).FondsproStadt = CType(Objekte(11), ObjektNumericUpDown).GetValue
                Objektverwalter.Spielfeld.Spieler(CPlayer).SetFonds(CType(Objekte(14), ObjektNumericUpDown).GetValue)
                Objektverwalter.Spielfeld.Spieler(CPlayer).Team = CType(Objekte(15), ObjektDropDownMenue).GetItem
                Objektverwalter.Spielfeld.Spieler(CPlayer).KIStufe = [Enum].Parse(ObjektSpieler.KIStufen.Einfach.GetType, CType(Objekte(17), ObjektDropDownMenue).GetItem)
        End Select
        DoubleClick = False
    End Sub


#End Region
End Class